package com.ruoyi.web.controller.diagnosis;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.diagnosis.domain.Detail;
import com.ruoyi.diagnosis.service.IDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史记录Controller
 * 
 * @author fansea
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/diagnosis/record")
public class DetailController extends BaseController
{
    @Autowired
    private IDetailService detailService;

    /**
     * 查询历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(Detail detail)
    {
        startPage();
        List<Detail> list = detailService.selectDetailList(detail);
        return getDataTable(list);
    }

    /**
     * 导出历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:export')")
    @Log(title = "历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Detail detail)
    {
        List<Detail> list = detailService.selectDetailList(detail);
        ExcelUtil<Detail> util = new ExcelUtil<Detail>(Detail.class);
        util.exportExcel(response, list, "历史记录数据");
    }

    /**
     * 获取历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:query')")
    @GetMapping(value = "/{figureId}")
    public AjaxResult getInfo(@PathVariable("figureId") Long figureId)
    {
        return success(detailService.selectDetailByFigureId(figureId));
    }

    /**
     * 新增历史记录
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:add')")
    @Log(title = "历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Detail detail)
    {
        return toAjax(detailService.insertDetail(detail));
    }

    /**
     * 修改历史记录
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:edit')")
    @Log(title = "历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Detail detail)
    {
        return toAjax(detailService.updateDetail(detail));
    }

    /**
     * 删除历史记录
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:record:remove')")
    @Log(title = "历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{figureIds}")
    public AjaxResult remove(@PathVariable Long[] figureIds)
    {
        return toAjax(detailService.deleteDetailByFigureIds(figureIds));
    }
}
